home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / util / wb / RunBar31.lha / RunBar / Develop / Source / CpuControl.src / CpuControl.c < prev    next >
C/C++ Source or Header  |  1996-11-23  |  6KB  |  189 lines

  1.  
  2. #include <proto/exec.h>
  3. #include <proto/dos.h>
  4. #include <proto/runbar.h>
  5. #include <exec/execbase.h>
  6. #include <exec/memory.h>
  7.  
  8. void VBRtest(void); /* VBR test procedure */
  9. void VBRMove(void); /* VBR move procedure */
  10.  
  11. struct Library *RunBarBase; /* Library Base*/
  12.  
  13. /* CPU Image */
  14. UWORD chip cpuData[39] =
  15. {
  16.     /* Plane 0 */
  17.     0x0000,0x0000,0x2AA0,0x1FE0,0x3FE0,0x1FE0,0x3860,0x1FE0,
  18.     0x3060,0x1FE0,0x3FE0,0x0000,0x0000,
  19.     /* Plane 1 */
  20.     0x0000,0x1540,0x1540,0x6030,0x0800,0x6030,0x0780,0x6030,
  21.     0x0F80,0x6030,0x1540,0x1540,0x0000,
  22.     /* Plane 2 */
  23.     0x0000,0x0000,0x0A80,0x0000,0x2820,0x0000,0x27A0,0x0000,
  24.     0x2FA0,0x0000,0x0A80,0x0000,0x0000
  25. };
  26.  
  27. struct Image cpu =
  28. {
  29.     0, 0,        /* LeftEdge, TopEdge */
  30.     13, 13, 3,    /* Width, Height, Depth */
  31.     cpuData,    /* ImageData */
  32.     0x0007, 0x0000,    /* PlanePick, PlaneOnOff */
  33.     NULL        /* NextImage */
  34. };
  35.  
  36.  
  37. /* Menu Structure */
  38. struct SBItem menu[]=
  39. {
  40.   {0,NULL},         /* 0 - Normal, 1 - Disabled */ 
  41.   {0,NULL},         /* 2 - Bar   ,15 - Menu End */
  42.   {2,NULL},
  43.   {0,"Exit"},
  44.   {15,NULL}     
  45. };
  46.  
  47. /* Information about Menu */
  48. struct RBInfo info =
  49. {
  50.   RB_VERSION,     /* Always set it to RB_VERSION*/
  51.   "CpuControl",/* Menu name.Please use specific name, because */
  52.                   /* this name will use for unique check. */
  53.   RBF_UNIQUE      /* Will not allow duplicates. */
  54. };
  55.  
  56.     ULONG  vbp;
  57. static  char   ver[]="$VER: CPU Control by Sergej Kravcenko 1.0 (24.11.96)";
  58. /*--------------------Main Program-------------------------*/
  59. void main()
  60.     struct Task *prtask;
  61.     char   line1[]="VBR to FAST";
  62.     char   line2[]="VBR to CHIP";
  63.     char   line3[]="Enable Cache";
  64.     char   line4[]="Disable Cache";
  65.     BOOL   my_close,cache,vbr;
  66.     struct MsgPort *port;
  67.     struct RBMessage *my_message;
  68.     UWORD  Flags;
  69.     ULONG  fastmem,cachestate,mask;
  70.     struct ExecBase *SysBase=*(struct ExecBase **)4;
  71.     ULONG  class,code,cputype; /* cputype 0 - 000 or 010,1 - 020,2 - 030 */
  72.                                /* 3 - 040,4 - 060                 */
  73.     
  74. /*---------------Open Library------------------------------*/    
  75.     RunBarBase = (struct Library *)
  76.     OpenLibrary( "RunBar.library",1);
  77.   
  78.     if( RunBarBase == NULL) goto end;
  79.     
  80. /*------------------Get Task Pointer-----------------------*/    
  81.     prtask = FindTask(NULL);
  82.     
  83. /*-------------------Get CPU Type--------------------------*/    
  84.     Flags = SysBase->AttnFlags;
  85.     cputype = 0;
  86.     if ((Flags&0x0002) != 0)
  87.         cputype = 1;
  88.     if ((Flags&0x0004) != 0)
  89.         cputype = 2;
  90.     if ((Flags&0x0008) != 0)
  91.         cputype = 3;
  92.     if ((Flags&0x0080) != 0)
  93.         cputype = 4;
  94. /*------------Check Fast Mem------------------------------*/ 
  95.     Forbid();
  96.     fastmem = AvailMem(MEMF_FAST);
  97.     Permit();
  98. /*---Quit if 68000 CPU and no FAST memory------------*/
  99.     if ((fastmem < 1024) && (cputype == 0)) goto end;
  100.  
  101. /*----------Get Info about Cache and VBR state---------*/
  102.     cachestate = CacheControl(0x00000000,0x00000000);
  103.     if ((cachestate & 0x00000001) != 0) cache = TRUE;
  104.     else cache = FALSE;
  105.     
  106.     Supervisor((unsigned long (* )())VBRtest);
  107.     if (vbp != 0)  vbr = TRUE;
  108.     else vbr = FALSE;  
  109.  
  110.     if (cputype > 1) mask = 0x00001111;
  111.     else mask = 0x00000001;
  112. /*------------------Layout Menu-----------------------*/
  113.     if (fastmem < 1024)
  114.     menu[1].sbi_Type = 1;
  115.     else
  116.      if (vbr == TRUE) menu[1].sbi_Name = line2;
  117.         else menu[1].sbi_Name = line1;
  118.         
  119.     if (cputype == 0) menu[0].sbi_Type = 1;
  120.     else
  121.      if (cache == TRUE) menu[0].sbi_Name = line4;
  122.         else menu[0].sbi_Name = line3;             
  123. /*------------------Create RunBar Menu---------------------*/    
  124.     if (RB_AddTask(prtask,menu,&cpu,&info,&port) != 0) goto end;
  125.     
  126. /*------------------Wait Port------------------------------*/    
  127.     my_close = FALSE;
  128.     while( my_close == FALSE )
  129.     {
  130.      WaitPort(port);
  131.      my_message = (struct RBMessage *) GetMsg(port);
  132.      if (my_message)
  133.      {
  134.         class    = my_message->rb_class;
  135.         code     = my_message->rb_code;
  136.         ReplyMsg((struct Message *) my_message );
  137.         
  138.         if(class == IDCMP_RUNBARCMD)
  139.          {
  140.           switch (code)
  141.           {
  142.             case 0:
  143.               if (cache == FALSE)
  144.               {
  145.                cache = TRUE; 
  146.                CacheControl(0x00001111,mask);
  147.               }
  148.               else
  149.               {
  150.                cache = FALSE; 
  151.                CacheControl(0x00000000,mask);
  152.               }
  153.               if (cache == TRUE) menu[0].sbi_Name = line4;
  154.                  else menu[0].sbi_Name = line3;
  155.               RB_Edit(prtask,menu,&cpu);   
  156.             break;
  157.             case 1:
  158.               VBRMove();
  159.               Supervisor((unsigned long (* )())VBRtest);
  160.               if (vbp != 0)  vbr = TRUE;
  161.               else vbr = FALSE;
  162.               if (vbr == TRUE) menu[1].sbi_Name = line2;
  163.               else menu[1].sbi_Name = line1;
  164.               RB_Edit(prtask,menu,&cpu);
  165.             break;
  166.             case 3:
  167.              my_close = TRUE;
  168.             break;  
  169.           }   
  170.          } 
  171.         if (class == IDCMP_RUNBARMSG)
  172.            {
  173.        /*------------Exit--------------------*/     
  174.              if (code == RB_REMOVE) my_close = TRUE;      
  175.            }                          
  176.        
  177.      }
  178.     }
  179. /*------------Remove RunBar Menu---------------------*/
  180. /* If you get non NULL result, you must wait some time, and try */
  181. /* again. */
  182.     
  183.     while (RB_RemoveTask(prtask)) Delay(10);
  184.     
  185. /*-----------Close Library---------------------------*/    
  186. end:if ( RunBarBase ) CloseLibrary ((struct Library *) RunBarBase);   
  187. }
  188.